//1、实现对圆形、三角形、长方形求面积

package main

import (
	"fmt"
	"math"
)

type Shape interface {
	area() float64
}

type triangleShape struct {
	length float64
	height float64
}

func (a *triangleShape) area() float64 {
	return a.length * a.height / 2
}

type circleShape struct {
	r float64
}

func (a *circleShape) area() float64 {
	return a.r * a.r * math.Pi
}

type rectangleShape struct {
	width  float64
	length float64
}

func (a *rectangleShape) area() float64 {
	return a.width * a.length
}

func main() {
	a := triangleShape{3.4, 1.7}
	fmt.Printf("a.area(): %.3v\n", a.area())
	b := circleShape{5}
	fmt.Printf("b.area(): %.3v\n", b.area())
	c := rectangleShape{3, 4}
	fmt.Printf("c.area(): %.3v\n", c.area())
	var d Shape
	d = &c
	fmt.Printf("d.area(): %.3v\n", d.area())
	d = &b
	fmt.Printf("d.area(): %.3v\n", d.area())

}
